Completed
Pull Request — master (#1653)
by Aristeides
04:15 queued 02:06
created

  A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
wp.customize.controlConstructor['kirki-number'] = wp.customize.kirkiDynamicControl.extend({
2
3
	initKirkiControl: function() {
4
5
		var control = this,
0 ignored issues
show
Coding Style introduced by
As per coding-style, prefer block-scoped variables using let or const which have better semantics than var.

Since ECMAScript 6, you can create block-scoped vars or constants with the keywords let or const. These variables/constants are only valid in the code block where they have been declared.

Consider the following two pieces of code:

if (true)
 {
    var x = "Hello, Stonehenge!";
}

console.log(x); //prints Hello, Stonehenge! to the console

and

if (true)
 {
    let x = "Hello, Stonehenge!";
}

console.log(x); //ReferenceError: x is not defined

The variable is not defined otuside of its block. This limits bleeding of variables into other contexts.

To know more about this ECMA6 feature, look at the MDN pages on let and const.

Loading history...
6
		    value   = control.setting._value,
7
		    html    = '',
8
		    input,
9
		    up,
10
		    down;
11
12
		// Make sure we use default values if none are define for some arguments.
13
		control.params.choices = _.defaults( control.params.choices, {
14
			min: 0,
15
			max: 100,
16
			step: 1
17
		} );
18
19
		// Make sure we have a valid value.
20
		if ( isNaN( value ) || '' === value ) {
21
			value = ( 0 > control.params.choices.min && 0 < control.params.choices.max ) ? 0 : control.params.choices.min;
22
		}
23
		value = parseFloat( value );
24
25
		// If step is 'any', set to 0.001.
26
		control.params.choices.step = ( 'any' === control.params.choices.step ) ? 0.001 : control.params.choices.step;
27
28
		// Make sure choices are properly formtted as numbers.
29
		control.params.choices.min  = parseFloat( control.params.choices.min );
30
		control.params.choices.max  = parseFloat( control.params.choices.max );
31
		control.params.choices.step = parseFloat( control.params.choices.step );
32
33
		// Build the HTML for the control.
34
		html += '<label>';
35
		if ( control.params.label ) {
36
			html += '<span class="customize-control-title">' + control.params.label + '</span>';
37
		}
38
		if ( control.params.description ) {
39
			html += '<span class="description customize-control-description">' + control.params.description + '</span>';
40
		}
41
		html += '<div class="customize-control-content">';
42
		html += '<input ' + control.params.inputAttrs + ' type="text" ' + control.params.link + ' value="' + value + '" />';
43
		html += '<div class="quantity button minus">-</div>';
44
		html += '<div class="quantity button plus">+</div>';
45
		html += '</div>';
46
		html += '</label>';
47
48
		control.container.html( html );
49
50
		input = control.container.find( 'input' );
51
		up    = control.container.find( '.plus' );
52
		down  = control.container.find( '.minus' );
53
54
		up.click( function() {
55
			var oldVal = parseFloat( input.val() ),
0 ignored issues
show
Coding Style introduced by
As per coding-style, prefer block-scoped variables using let or const which have better semantics than var.

Since ECMAScript 6, you can create block-scoped vars or constants with the keywords let or const. These variables/constants are only valid in the code block where they have been declared.

Consider the following two pieces of code:

if (true)
 {
    var x = "Hello, Stonehenge!";
}

console.log(x); //prints Hello, Stonehenge! to the console

and

if (true)
 {
    let x = "Hello, Stonehenge!";
}

console.log(x); //ReferenceError: x is not defined

The variable is not defined otuside of its block. This limits bleeding of variables into other contexts.

To know more about this ECMA6 feature, look at the MDN pages on let and const.

Loading history...
56
			    newVal;
57
58
			newVal = ( oldVal >= control.params.choices.max ) ? oldVal : oldVal + control.params.choices.step;
59
60
			input.val( newVal );
61
			input.trigger( 'change' );
62
		} );
63
64
		down.click( function() {
65
			var oldVal = parseFloat( input.val() ),
0 ignored issues
show
Coding Style introduced by
As per coding-style, prefer block-scoped variables using let or const which have better semantics than var.

Since ECMAScript 6, you can create block-scoped vars or constants with the keywords let or const. These variables/constants are only valid in the code block where they have been declared.

Consider the following two pieces of code:

if (true)
 {
    var x = "Hello, Stonehenge!";
}

console.log(x); //prints Hello, Stonehenge! to the console

and

if (true)
 {
    let x = "Hello, Stonehenge!";
}

console.log(x); //ReferenceError: x is not defined

The variable is not defined otuside of its block. This limits bleeding of variables into other contexts.

To know more about this ECMA6 feature, look at the MDN pages on let and const.

Loading history...
66
			    newVal;
67
68
			newVal = ( oldVal <= control.params.choices.min ) ? oldVal : oldVal - control.params.choices.step;
69
70
			input.val( newVal );
71
			input.trigger( 'change' );
72
		} );
73
74
		this.container.on( 'change keyup paste click', 'input', function() {
75
			control.setting.set( jQuery( this ).val() );
76
		});
77
	}
78
});
79